<?php
/**
 * Groups module for XOOPS
 *
 * You may not change or alter any portion of this comment or credits
 * of supporting developers from this source code or any supporting source code 
 * which is considered copyrighted (c) material of the original comment or credit authors.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @copyright       The Groups Project http://code.google.com/p/groupsforxoops/
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
 * @package         groups
 * @since           2.3.0
 * @author          Hui Xiao < xh.8326@gmail.com >
 * @version         $Id: header.php Sat Jul 18 12:39:33 CST 2009
 */
if ( !defined("XOOPS_ROOT_PATH") )  die("XOOPS root path not defined");

include dirname(__FILE__) . '/include/theme.php';

$xoopsOption["template_main"] = 'db:' . $xoopsOption["template_main"];

if ( isset($_SERVER["HTTP_X_REQUESTED_WITH"]) && 
	$_SERVER["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest" &&
	$_SERVER["REQUEST_METHOD"] === "POST")  {
	$xoopsTpl= new XoopsTpl();
} else {
	$options = array(
		'themePath' 		=> XOOPS_ROOT_PATH . '/modules/groups',
		'folderName'		=> 'theme',
		'contentTemplate' 	=> $xoopsOption["template_main"] ,
		'canvasTemplate'	=> "theme.html"
	);
	$xoTheme = new xoGroupTheme($options);
	$xoopsTpl = $xoTheme->getTemplate();
	$xoTheme->getDefAssign();

	$xoopsTpl->assign( array( 
	   'xoops_isuser' => false, 
	   'xoops_isadmin' => false ,
	   ) );

	if ( isset($xoopsUser) && is_object($xoopsUser) ) {
		$xoopsTpl->assign( array(
			'xoops_isuser' => true,
			'xoops_userid' => $xoopsUser->getVar('uid'),
			'xoops_uname' => $xoopsUser->getVar('uname'),
		) );
	}

	// Sets cache time
	if ( !empty($xoopsModule) ) {
		$xoTheme->contentCacheLifetime = @$xoopsConfig['module_cache'][ $xoopsModule->getVar('mid', 'n') ];
		// Tricky solution for setting cache time for homepage
	} elseif (!empty($xoopsOption['template_main'])) {
		$xoTheme->contentCacheLifetime = 604800;
	}
	if ( $xoTheme->checkCache() ) { exit(); }
}